<template>
	<view class="home">
		<!-- 支付宝自定义导航栏 -->
		<!-- #ifndef H5 -->
		<CustomBar />
		<!-- #endif -->
		<view class="content">
			<view class="home-focus-img">
				<!-- 轮播图区域 -->
				<!-- 				<swiper class="swiper" circular indicator-dots autoplay :interval="3000" :duration="1000">
					<swiper-item v-for="item in swiperList" :key="item.goods_id" @click="goDeatil(item)">
						<image :src="item.image_src">
					</swiper-item>
				</swiper> -->
			</view>
			<view class="nav-list common-margin">
				<view class="nav-item" v-for="(item,index) in navList" :key="index" @click="navClickHandler(item)">
					<image :src='`../../static/images/${item.icon}.svg`' mode="aspectFill" class="nav-img"></image>
					<view>{{item.title}}</view>
				</view>
			</view>
			<view class="recently-updated common-panel common-margin">
				<view class="title">最近上新</view>
				<scroll-view scroll-x class="scrollContainer" v-if="scoreRankeBikeList.length > 0">
					<view v-for="item in [...recentlyUpdatedBikeList]" :key="item.id" class="scoreRankeBike"
						@click="goBikeDetail(item)">
						<image :src="imgUrl + item.img.split(',')[0]"></image>
						<view class="bold">{{item.brandName}}</view>
						<view class="bold">{{item.name}}</view>
					</view>
				</scroll-view>
			</view>
			<view class="rate-ranking common-panel common-margin">
				<view class="title">网友评分排名</view>

				<scroll-view scroll-x class="scrollContainer" v-if="scoreRankeBikeList.length > 0">
					<view v-for="item in [...scoreRankeBikeList]" :key="item.id" class="scoreRankeBike"
						@click="goBikeDetail(item)">
						<image :src="imgUrl + item.img.split(',')[0]"></image>
						<view class="bold">{{item.brandName}}{{item.name}}</view>
						<view class="score">{{item.score}}</view>
					</view>
				</scroll-view>
				<view class="noScore" v-else>暂无评分</view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../api/index.js'
	import {
		imgUrl
	} from '../../util/index.js'
	export default {
		data() {
			return {
				imgUrl,
				navList: [{
						title: '品牌',
						pageUrl: '/pages/brand/brand',
						icon: 'pinpai'
					},
					{
						title: '性价比',
						pageUrl: '',
						icon: 'xingjiabi'
					},
					{
						title: '个性化',
						pageUrl: '/pages/individualization/individualization',
						icon: 'gexinghua'
					}
				],
				scoreRankeBikeList: [],
				recentlyUpdatedBikeList: []
			}
		},
		onLoad() {
			this.getBikeScoreRanKeList()
			this.getRecentlyUpdatedList()
		},
		methods: {
			goBikeDetail(item) {
				// const token = uni.getStorageSync('token')
				// if (token) {
				// 	uni.navigateTo({
				// 		url: `/pages/bikeDetail/bikeDetail?bikeId=${item.id}&&bikeType=${item.bikeType}`
				// 	})
				// } else {
				// 	uni.navigateTo({
				// 		url: '/pages/login/login'
				// 	})
				// }
				uni.navigateTo({
					url: `/pages/bikeDetail/bikeDetail?bikeId=${item.id}&&bikeType=${item.bikeType}`
				})
			},
			navClickHandler(item) {
				uni.navigateTo({
					url: item.pageUrl
				})
			},
			getBikeScoreRanKeList() {
				request('/bike/scoreRanking/list', {}, 'GET').then(res => {
					if (res.status === 0) {
						this.scoreRankeBikeList = res.data
					}
				})
			},
			getRecentlyUpdatedList() {
				request('/bike/recentlyUpdated/list', {}, 'GET').then(res => {
					if (res.status === 0) {
						this.recentlyUpdatedBikeList = res.data
					}
				})
			}
		},
		async onPullDownRefresh() {
			uni.stopPullDownRefresh();
		},
		onShow() {
			// #ifdef MP-ALIPAY
			uni.setNavigationBar({
				frontColor: '#0000',
				backgroundColor: '#ffffff',
			})
			// #endif
		},
	}
</script>

<style lang="scss" scoped>
	.home {
		width: 100%;
		height: 100vh;
		background: linear-gradient(#CFEAFF, #FFF);

		.content {
			overflow: hidden;
			// margin: 0 50rpx 50rpx;
			box-sizing: border-box;

			.nav-list {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 40rpx;
				line-height: 1.5;
				margin: 50rpx !important;

				.nav-item {
					text-align: center;

					image {
						width: 70rpx;
						height: 70rpx;
					}
				}
			}

			.recently-updated {}

			.rate-ranking {}

			.common-margin {
				margin: 0 50rpx 50rpx;
			}

			.common-panel {
				.title {
					font-size: 20px;
					line-height: 1.5;
					margin-bottom: 10rpx;
				}

				.scrollContainer {
					width: 100%;
					white-space: nowrap;

					.scoreRankeBike {
						display: inline-block;
						width: 44%;
						text-align: center;
						margin-right: 20rpx;

						image {
							width: 100%;
							height: 250rpx;
							object-fit: cover;
							display: block;
						}

						.bold {
							margin-top: 10rpx;
							font-size: 30rpx;
							width: 100%;
							overflow-x: auto;
						}

						.score {
							font-size: 30rpx;
							margin-top: 10rpx;
						}
					}
				}
			}
		}
	}
</style>
